package com.heima.minio;

import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;


import java.io.FileInputStream;


/**
 * Minio测试类
 *
 * @Author mr.lin
 * @Date 2025/1/25 0:24
 */
public class MinioTest {
    public static void main(String[] args) throws Exception {
        //4.创建文件输入流
        FileInputStream fileInputStream = new FileInputStream("G:\\test.html");

        //1.创建minio请求对象
        MinioClient minioClient = MinioClient.builder()
                .credentials("minio", "minio123")
                .endpoint("http://192.168.200.188:9000")
                .build();
        //3.构建请求条件
        PutObjectArgs putObject = PutObjectArgs.builder()
                .object("test1.html") // 指定上传文件名称
                .contentType("text/html") //指定文件类型
                .bucket("leadnews") // 指定存储桶名称
                .stream(fileInputStream, fileInputStream.available(), -1)
                .build();
        //2.执行上传操作
        minioClient.putObject(putObject);

        System.out.println("http://192.168.200.188:9000/leadnews/test.html");
    }
}
